package com.peng.sell.converter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.peng.sell.dataobject.OrderDetail;
import com.peng.sell.dto.OrderDTO;
import com.peng.sell.form.OrderForm;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class OrderForm2OrderDTOConverter {
    public static OrderDTO converter(OrderForm orderForm){
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setBuyerPhone(orderForm.getPhone());
        orderDTO.setBuyerName(orderForm.getName());
        orderDTO.setBuyerAddress(orderForm.getAddress());
        orderDTO.setBuyerOpenid(orderForm.getOpenid());
        List<OrderDetail> orderDetailList = JSON.parseObject(orderForm.getItems(),new TypeReference<ArrayList<OrderDetail>>(){});
        orderDTO.setOrderDetailList(orderDetailList);
        return orderDTO;
    }
}
